package com.muyu.jarpackagedemo.controller;

import com.alibaba.fastjson2.JSONObject;
import com.muyu.jarpackagedemo.controller.vo.TestVO;
import com.muyu.jarpackagedemo.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName: TestController
 * @Author: Zirun.Xin
 * @Date: 2025/3/31 下午4:19
 * @Version: 1.0
 * @Description: 测试控制层
 */
@Slf4j
@RestController
@RequestMapping(value = "/api/v1/test")
public class TestController {

    @Autowired
    private HttpServletRequest httpServletRequest;

    /**
     * 测试演示
     * @param input 输入内容
     * @return 响应结果集
     */
    @GetMapping(value = "/demo")
    public Result<TestVO> demo(@RequestParam(value = "input") String input) {
        Result<TestVO> result = Result.<TestVO>builder()
                .code(200)
                .message("成功")
                .timestamp(System.currentTimeMillis())
                .data(TestVO.builder().print(input).build())
                .build();

        log.info("api接口：【测试演示】，路径：【{}】，请求方式：【{}】，请求参数：【{}】，响应参数：【{}】",
                httpServletRequest.getRequestURI(), httpServletRequest.getMethod(),
                input, JSONObject.toJSONString(result));

        return result;
    }
}
